var mailer = require('nodemailer');
var smtpTransport = require('nodemailer-smtp-transport')
var settings = require('../settings');
var transporter = mailer.createTransport(smtpTransport(settings.mail_opts));
var SITE_ROOT_URL = "http://" + settings.host;
var util = require('util');

var sendMail = function(data){
  transporter.sendMail(data, function(err){
    console.log(err)
  })
};

exports.sendMail = sendMail;

exports.sendActiveMail = function(who, token, name){
  var from = util.format('%s <%s>', settings.name, settings.mail_opts.auth.user);
  var to = who;
  var subject = settings.name + " 账号激活";
  var html = '<p>您好：'+name+'</p>'+
            '<p>我们收到了您的注册信息</p>'+
            '<a href = "'+SITE_ROOT_URL+'/active_account?key=' + token + '&name=' +
            name + '">激活链接</a>"' +
            '<p>若您没有在 xiaochao.site 注册过，说明有人滥用了您的电子邮件，对于给您造成的打扰感到非常抱歉';
  sendMail({
    from: from,
    to: to,
    subject: subject,
    html: html
  });
};
